package com.bmps.springcloud.insuredmicroservice.service.underwrite.strategy.insurance;

import com.bmps.springcloud.insuredmicroservice.config.accept.ProductConfig;
import com.bmps.springcloud.insuredmicroservice.constant.accept.AcceptConstant;
import com.bmps.springcloud.insuredmicroservice.constant.accept.UnderWriteConstant;
import com.bmps.springcloud.insuredmicroservice.model.accept.resquest.AcceptRequestDataModel;
import com.bmps.springcloud.insuredmicroservice.model.accept.resquest.CustInfoModel;
import com.bmps.springcloud.insuredmicroservice.model.accept.resquest.InsurantModel;
import com.bmps.springcloud.insuredmicroservice.model.accept.resquest.ProductModel;
import com.bmps.springcloud.insuredmicroservice.model.underwrite.InsuredModel;
import com.bmps.springcloud.insuredmicroservice.repository.underwrite.coresystem.InsuredCoreRepository;
import com.bmps.springcloud.insuredmicroservice.util.accept.AcceptUtil;

import java.util.List;

/**
 * description:
 *
 * @author jackdaw
 * @date 2020-08-23 23:44
 */
public class Neu003InsuranceStrategy implements InsuranceStrategy {
    @Override
    public InsuredModel checkInsuredRolesByRiskCode(AcceptRequestDataModel acceptRequestDataModel, InsuredCoreRepository insuredCoreRepository, ProductModel productModel, ProductConfig productConfig) {
        //被保人信息
        CustInfoModel custInfoModel = acceptRequestDataModel.getRequest().getCustInfo();
        List<InsurantModel> insurantModelList = custInfoModel.getInsurants().getInsurant();
        InsurantModel insurantModel = AcceptUtil.getInsurantModelBySeq(productModel.getProdInsSeq(), insurantModelList);
        //投保人与被保人的关系：本人、配偶、父母和子女
        if (!(productConfig.getRelationList().contains(insurantModel.getRelToApp()))) {
            return AcceptUtil.getInsuredResponse(UnderWriteConstant.UNDER_WRITE_FIAL_CODE,
                    String.format(UnderWriteConstant.UNDER_WRITE_NUGG0007_MESSAGE));
        }
        //被保人职业类别：1-6
        if (!(AcceptConstant.OCCUPATION_ONE_TO_SIX.contains(insurantModel.getOccupationType()))) {
            return AcceptUtil.getInsuredResponse(UnderWriteConstant.UNDER_WRITE_FIAL_CODE,
                    String.format(UnderWriteConstant.UNDER_WRITE_NPGG0028_MESSAGE, insurantModel.getOccupationType()));
        }

        return AcceptUtil.getInsuredResponse(AcceptConstant.RESULT_SUCCESS_CODE,
                String.format(AcceptConstant.RESULT_SUCCESS_MESSAGE));
    }
}
